package com.example.myapplication.room;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import java.util.List;

public class AtadaperRoom extends RecyclerView.Adapter<AtadaperRoom.ViewHolder>{


    private List<Student> studentList;

    public AtadaperRoom(List<Student> studentList) {
        this.studentList = studentList;
    }


    @NonNull
    @Override
    public AtadaperRoom.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.room_item_layout, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull AtadaperRoom.ViewHolder holder, int position) {

        holder.name.setText(studentList.get(position).getName());
        holder.age.setText(studentList.get(position).getAge() + "");
    }


    @Override
    public int getItemCount() {
        return studentList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        TextView age;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
            age = itemView.findViewById(R.id.tv_age);

        }
    }
}
